package cc.magicjson.p6spy.config;

import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
import org.hibernate.engine.jdbc.internal.FormatStyle;
import org.springframework.util.StringUtils;

import static org.apache.logging.log4j.util.Strings.isNotBlank;

public class P6SpyFormatter implements MessageFormattingStrategy {

    @Override
    public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) {
//        StringBuilder sb = new StringBuilder();
//        sb.append(now)
//            .append(" | Elapsed time: ").append(elapsed).append("ms | ")
//            .append("Connection ID: ").append(connectionId)
//            .append(" | URL: ").append(url)
//            .append("\n");
//
//        if (sql != null && !sql.trim().isEmpty()) {
//            String formattedSql = FormatStyle.BASIC.getFormatter().format(sql);
//            sb.append("Executed SQL: \n").append(formattedSql).append("\n");
//        }
//
//        return sb.toString();
        return isNotBlank(sql) ? " Consume Time：" + elapsed + " ms " + now +
            "\n Execute SQL：" + sql.replaceAll("[\\s]+", " ") + "\n" : "";
    }
}
